package com.wu.controller;

import com.wu.entity.User;
import com.wu.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 20521
 */
@Api(tags = "用户管理")
@RestController
public class UserController {
    @Autowired
    public UserService userService;
    @ApiOperation(value = "用户查询",notes = "查询所有用户")
    @GetMapping("queryUserList")
    public List<User> queryUserList() {
        return userService.queryUserList();
    }

    @ApiOperation(value = "用户新增",notes = "新增一个用户")
    @PostMapping("/addUser")
    public String addUser(User user) {
        boolean result = userService.addUser(user);
        if (result) {
            return "新增成功";
        } else {
            return "新增失败";
        }
    }
    @ApiOperation(value = "用户新增",notes = "批量新增用户")
    @PostMapping("/addListUser")
    public String addListUser(@RequestBody List<User> userList) {
        for (User user1 : userList) {
            boolean result = userService.addUser(user1);
            if (!result) {
                return "批量新增失败";
            }
        }
        return "批量新增成功";
    }

    @ApiOperation(value = "用户删除",notes = "根据用户名称删除用户")
    @DeleteMapping("/deleteUser")
    public String deleteUser(String name) {
        boolean b = userService.delUser(name);
        if (b) {
            return "删除成功";
        } else {
            return "删除失败";
        }

    }
}
